package com.application.service.Impl;


import com.application.dao.LeaderDao;
import com.application.domain.User;
import com.application.domain.Leader;
import com.application.service.LeaderService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LeaderServiceImpl implements LeaderService {
    @Autowired
    LeaderDao leaderDao;


    //用来查看更新数据的用户  是否是真的负责人
    @Override
    public int check(User user) {
        //   就是  点击 更新的时候   把 更新的用户的信息传过来  然后截取相关的数据  进行判断
        Leader leader = new Leader();
        leader.setName(user.getUsername());
        leader.setTel(user.getTel());
        leader.setCommunity(user.getCommunity());

        Leader check = leaderDao.check(leader);
        if(check !=null){
            return 1;
        }
        return 0;
    }

    @Override
    public int save(Leader leader) {
        int insert = leaderDao.insert(leader);
        return insert;
    }

    @Override
    public int deleteById(String id) {
        int deleteById = leaderDao.deleteById(id);
        return deleteById;
    }

    @Override
    public int updateById(Leader leader, String id) {
        LambdaQueryWrapper<Leader> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Leader::getId,id);
        int update = leaderDao.update(leader, lqw);
        return update;
    }

    @Override
    public int updateByOpenid(Leader leader, String openid) {
        LambdaQueryWrapper<Leader> lqw= new LambdaQueryWrapper<>();
        lqw.eq(Leader::getOpenid,openid);
        int update = leaderDao.update(leader,lqw);
        return update;
    }
}
